﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Zj.DDDSample.Domain.Events;
using Zj.DDDSample.Domain.Projects;

namespace Zj.DDDSample.EventHandler
{
    public class ProjectCreatedEventHandler
        : IEventHandler
    {
        public bool CanHandle(IEvent @event)
        {
            return @event.GetType() == typeof(ProjectCreatedEvent);
        }

        //public Task<bool> HandleAsync(ProjectCreatedEvent @event, CancellationToken cancellationToken = default(CancellationToken))
        //{
        //    return  CanHandle(@event)?HandleAsync(@event, cancellationToken) :Task.FromResult(false);
        //}

        public Task<bool> HandleAsync(IEvent @event, CancellationToken cancellationToken = default(CancellationToken))
        {
            return CanHandle(@event) ? HandleAsync((ProjectCreatedEvent)@event, cancellationToken) : Task.FromResult(false);
        }
    }
}
